home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / recent / poolme.rea < prev    next >
Text File  |  1998-06-26  |  23KB  |  539 lines

  1. Short:    Memory defragmentizer/AllocP superset
  2. Author:   thor@math.tu-berlin.de (Thomas Richter)
  3. Uploader: thor@math.tu-berlin.de (Thomas Richter)
  4. Version:  1.40
  5. Type:     util/sys
  6. Requires: OS 3.0
  7.  
  8. ______________________________________________________________________________
  9.  
  10.         Compatibility notes, other remarks
  11. ______________________________________________________________________________
  12.  
  13. The linux kernal boot program "amiboot" does not work with PoolMem installed.
  14. This program suffers from several bugs. First of all, it examines the
  15. memory list itself, without using the exec.library. (What do you think
  16. AvailMem() is good for, then?) Second, it does not even call Forbid() to
  17. do so. Third, it always expects that the chip memory comes in one continous
  18. block and is too unflexible to handle other cases, as for example the two
  19. ChipMem blocks that will be created when PoolMem is running and active.
  20. If you really MUST use this program, then use the SCRATCHONLY option of
  21. PoolMem to avoid splitting the memory in a large and a small memory pool.
  22. ______________________________________________________________________________
  23.  
  24. The game demo "The Final Odyssey" crashes when PoolMem is active. Tracing 
  25. this error down to its roots resulted in an aparent bug in the memory 
  26. deallocation function of this game that occurs, too, with MungWall instead 
  27. of PoolMem installed. Since EVERY CORRECT PROGRAM is supposed to run with 
  28. MungWall, I WON'T TRY to add a workaround for this bug. Just avoid buggy 
  29. programs, as usual. Thanks to Dirk Neubauer for the hint.
  30. ______________________________________________________________________________
  31.  
  32. Photogenics: I got reports that this program crashes with PoolMem installed
  33. as soon as it is shut down. A bug in the shutdown code alters memory that
  34. is no longer allocated. THIS IS FATAL, even without PoolMem. It's just a 
  35. matter of good luck if that does not crash the system. This hit cannot
  36. be detected with MungWall since pgs called Forbid(). MemSniff will do a 
  37. better job in these cases...
  38. ______________________________________________________________________________
  39.  
  40. The mouse driver in the XiPaint program contains a serious bug that can
  41. cause crashes, with or without PoolMem.
  42.  
  43. The message handling of the mouse driver is broken. After a long debug 
  44. session deep in the night, I found that the crashes were created by the
  45. mouse driver XMouse. It replies messages that are no longer valid and have
  46. been FreeMem()'d before. THIS IS DEFINITELY ILLEGAL AND NOT A POOLMEM PROBLEM.
  47.  
  48. To help you checking other programs as well, I included a tiny patch
  49. "PatchReplyMsg". You shouldn't install it permanently, though, because it
  50. slows down the message system. If, after installation of this patch, a 
  51. program crashes with guru 0x01000001f, THEN THIS PROGRAM HAS THE SAME BUG
  52. AS XIPAINT and replies illegal messages. This will crash your system anyways,
  53. with or without PoolMem. Please sent a bug report to the author, or remove
  54. these programs. As I said, THIS IS NO POOLMEM problem.
  55.  
  56. The guru 0x01000013 is rather typical for these programs - they invalidate
  57. the internal scratch list of PoolMem.
  58. ______________________________________________________________________________
  59.  
  60. To "SaferPatches" users: 
  61.  
  62. To be able to remove PoolMem later on safely, PoolMem must be run AFTER 
  63. SaferPatches has been installed. Same goes of course for all other patches
  64. and the SaferPatches program.
  65. ______________________________________________________________________________
  66.  
  67. Developpers should check the "Developper.readme" file in this archive. It
  68. contains information about how to allocate and deallocate memory correctly.
  69. THESE AREN'T POOLMEM SPECIFIC INFORMATIONS! ALL OS FRIENDLY PROGRAMS HAVE
  70. TO OBEY THE RULES FORMULATED IN THIS FILE, they aren't my inventions.
  71. ______________________________________________________________________________
  72.  
  73. It has been reported that PoolMem runs astonishingly slow on PowerUp boards.
  74. I've currently no explanation for this, if you've any idea about it or know
  75. how to fix it - please report!
  76. ______________________________________________________________________________
  77.  
  78. SetPatch, the 68040.library and ppc.boards:
  79.  
  80. The 68040 library which is loaded by this program seems to allocate the 
  81. MMU tables in a strange way incompatible to the scratch list of PoolMem. 
  82.  
  83. Easy solution: run PoolMem after SetPatch. This compatibility problem 
  84. *should* have been fixed with the 1.31 version, but hasn't been tested 
  85. since I've only a '030 on board. (Sponsors welcome, though... ;-) )
  86. ______________________________________________________________________________
  87.  
  88. MemSniff:    (The THOR MungWall replacement)    
  89.  
  90. Patches deep into the memory allocation routines, too deep for PoolMem.
  91.  
  92. ______________________________________________________________________________
  93.  
  94. Additional nodes, compatibility hacks invented so far:
  95.  
  96. o) Programs that rely on a "correctly" set zero condition code of AllocMem()
  97.    ("PixMate")
  98.  
  99. o) the FFS/OFS ACTION_CLOSE bug that does not set the correct result code.
  100. This is currently done by the PoolMem FreeMem() replacement routine. However,
  101. the author of the FFS ("Heinz") has been informed, so it's likely that this
  102. error will be fixed in the next FFS release, probably for the FFS of the
  103. 3.5 workbench.
  104. ______________________________________________________________________________
  105.  
  106.             Version History
  107. ______________________________________________________________________________
  108.  
  109. 1.40:
  110.  
  111. - Integrated partially the PatchRAM AllocVec() patch. Memory requests by the
  112.   RAM disk are now allocated in reverse order. This feature can be turned off
  113.   explicitly by the NORAMREVERSE option, see below. 
  114.   Thanks to Raphael Pilarczyk for testing.
  115.  
  116. ______________________________________________________________________________
  117.  
  118. 1.35:
  119.  
  120. - Added a patch for the AvailMem() function to include the bytes in the 
  121.   scratch list.
  122. - Added the ALLOC32 keyword. See below for caveats! You usually DO NOT
  123.   want this!
  124.  
  125. ______________________________________________________________________________
  126.  
  127. 1.34:
  128.  
  129. - Added the SMALLHEADER keyword. A selected memory block can be set aside
  130.   for the small memory blocks explicitly.
  131. - Fixed a documentation error in the Developpers.readme. Thanks, Dave!
  132.  
  133. ______________________________________________________________________________
  134.  
  135. 1.33:
  136.  
  137. - Removed a bug in the PoolMem shutdown code. The pre-1.33 releases did not
  138.   free the scratch list completely.
  139. - Added the SCRATCHONLY keyword, it installs only the "scratchlist" of
  140.   PoolMem, not the dynamic pools.
  141. - Added the PUDDLESIZE, PUDDLETHRES and SHRINKTHRES keywords to make the 
  142.   parameters of the small memory pool adjustable.
  143. - Rewrote a lot of the kernal routines, mostly for optimizations.
  144. ______________________________________________________________________________
  145.  
  146. 1.32:
  147.  
  148. - Rewrote the startup segment completely. All 1.2 compatible code, argument
  149.   parser etc... removed. 
  150. - Added a proper version check. PoolMem requires OS 3.0.
  151. - Added the NOMERGE option to avoid merging of FastMem of different speed.
  152. - As a result of the new argument parser, the CHIPFWD option DOES NO LONGER
  153.   include the "INSTALL" option, both arguments should be given.
  154. - The PoolMem algorithms hasn't been changed, though.
  155. - Included new versions of PatchRAM and ShowMem.
  156. - PoolMem 1.31 and above works fine on PowerUp-Systems. Thanks to Andreas
  157.   Kleinert for testing! However, the current version does not yet adjust
  158.   memory correctly for the PowerUp system, that's still left to the ppc.lib
  159.   and AllocP32. Might change in the future, though.
  160. ______________________________________________________________________________
  161.  
  162. 1.31:
  163.  
  164. PoolMem includes a patch for AllocAbs() to be able to allocate absolute memory
  165. from the scratch list. This *should* help to make PoolMem working with the
  166. 68040/68060/ppc library, thus, it should be possible to run PoolMem IN FRONT
  167. of these libraries, i.e. "SetPatch". Would be nice if somebody could sent me 
  168. a report whether this works now or not.
  169.  
  170. Additionally, new versions of the FragMeter and ShowMem program are included.
  171. ______________________________________________________________________________
  172.  
  173. 1.30:
  174.  
  175. This version introduces a major rewrite of all critical routines, especially
  176. the replacement AllocMem() and FreeMem() routine. This might mean that either
  177. old bugs have been fixed or new bugs have been introduced. Anyways, check out
  178. for possible bugs since this is a release with a "0" in the version.
  179. This version might be much faster than the 1.2x version, due to some 
  180. optimizations.
  181. WARNING: Since the new 1.30 release of PoolMem replaces the Exec memory
  182. functions completely, YOU MUST RUN POOLMEM IN FRONT OF OTHER MEMORY PATCHES.
  183. ESPECIALLY, RUN POOLMEM FIRST, MUNGWALL AFTERWARS or Mungwall will be non-
  184. functional.
  185.  
  186. _____________________________________________________________________________
  187.  
  188. 1.22:
  189.  
  190. PoolMem merges now automatically all adjacent memory lists of the same type.
  191.  
  192. ______________________________________________________________________________
  193.  
  194. 1.21.1:
  195.  
  196. Included a new version of PatchRAM (check PatchRAM.readme for details),
  197. and a new version of the FragMeter program.
  198. _____________________________________________________________________________
  199.  
  200. 1.21:
  201.  
  202. PoolMem flushes now the memory as it should if called by AllocMem(-1,..).
  203. Except that, nothing changed.
  204. _____________________________________________________________________________
  205.  
  206. 1.20:
  207.  
  208. Added the CHIPFWD command. Works like INSTALL but allocates chip mem in
  209. standard (forwards) mode instead of backwards mode. Might solve strange
  210. compatibility problems. Added more sanity checks, included PatchReplyMsg
  211. to create warnings for broken programs.
  212. ______________________________________________________________________________
  213.  
  214. 1.19.1:
  215.  
  216. Changed the name of the DefragMeter to FragMeter because that makes more
  217. sense. Added a chunk count to this program. PoolMem itself unchanged.
  218. ______________________________________________________________________________
  219.  
  220. About PoolMem:
  221.     
  222.     If you run a lot of programs without resetting the system, you'll
  223. usually find that the main memory of the computer is getting "messed up",
  224. split in lots of tiny memory "snippets" that are more or less useless due to
  225. their tinyness. It may happen that you can't start an application even though
  226. enough memory is available - because this memory is too fragmentated to
  227. be of any use.
  228.  
  229. That's the point where PoolMem tries to help you: It manages the main memory
  230. in a way such that it can't get fragmentated too easely. It replaces also
  231. the function of AllocP, which is therefore obsolete.
  232. ______________________________________________________________________________
  233.  
  234. Installation and Usage:
  235.  
  236.     Copy the PoolMem program in this archive to the C: directory of your
  237. system partition. Add the following line to your startup-sequence:
  238.  
  239. PoolMem INSTALL >NIL:
  240.  
  241.  
  242. To remove PoolMem later on, open a shell window and enter
  243.  
  244. PoolMem remove
  245.  
  246.  
  247. The complete command template:
  248.  
  249. HELP/S,REMOVE/S,INSTALL/S,CHIPFWD/S,NOMERGE/S,
  250. SCRATCHONLY/S,PUDDLESIZE/N,SHRINKTRHES/N,PUDDLETHRES/N
  251. SMALLHEADER/N,ALLOC32/S,NORAMREVERSE/S
  252.  
  253.  
  254. HELP:            Prints a small overview of the available options.
  255.  
  256. REMOVE:            Remove a previously installed version of PoolMem.
  257.  
  258. INSTALL:        Install the PoolMem patch.
  259.  
  260. CHIPFWD:        Don't allocate big chunks of chip memory in reverse
  261.             direction. 
  262.             NOTE: Starting with 1.32, this is no longer a
  263.             stand-alone option, INSTALL must be given, too.
  264.  
  265. NOMERGE:        Do not attempt to merge adjacent memory blocks of
  266.             the same type. Even if the memory types are equal,
  267.             the physical characteristics of the memory blocks
  268.             might differ (e.g. 32 bit memory vs. 16 bit memory).
  269.             Future versions of PoolMem might respect this.
  270.             fragmentation.
  271.  
  272. SCRATCHONLY:        Do to build memory pools for small block allocations,
  273.             but use the scratch list only.
  274.  
  275. PUDDLESIZE:        Set the "puddle size" for the small block memory pool.
  276.             If an allocation from the small memory pool fails, 
  277.             PoolMem attempts to enlarge the pool by this number
  278.             of bytes. Defaults to 8192.
  279.  
  280. PUDDLETHRES:        Set the "puddle threshold" for the small memory pool.
  281.             Allocations larger than this size are taken from the
  282.             large memory pool instead of the small memory pool.
  283.  
  284. SHRINKTHRES:        Set the "merge threshold". If more than PUDDLESIZE +
  285.             SHRINKTHRES bytes are unused at the end of the
  286.             small memory pool, the pool shrinks and the free
  287.             bytes enter the large pool. Defaults to 4096.
  288.  
  289. SMALLHEADER:        If this option is given, set the memory block of this
  290.             index aside and use it as small memory pool. The
  291.             argument is simply the number of the block in the
  292.             memory list, counting from zero, and can be found
  293.             by watching the output of ShowMem. The topmost memory
  294.             block is number 0, the next below 1 and so on.
  295.             This memory block MUST BE fast memory.
  296.             If this option is given, PoolMem does not try to
  297.             split any fast mem header, only the chip mem is
  298.             split.
  299.             The small memory block is sorted in just before the
  300.             chip memory, but is used for the small memory block
  301.             allocations as long as possible.
  302.  
  303. ALLOC32:        Align all memory allocations to 32 byte boundaries.
  304.  
  305. NORAMREVERSE:        Do not try to allocate memory for the RAM disk in
  306.             reverse order. Using this option is NOT recommended
  307.             since it may increase the fragmentation.
  308.             
  309. ______________________________________________________________________________
  310.  
  311. ALLOC32 Caveats:
  312.  
  313.     This keyword keeps memory allocations aligned to 32 byte boundaries,
  314.     which might be useful if dealing with PPC hardware - by using this
  315.     keyword, the PPC cachelines can't overlap with the MC68K series
  316.     cacheline.
  317.  
  318.     HOWEVER, using this keyword fragmentizes the memory really badly
  319.     because of the unuseful unaligned boundary snippets that neither
  320.     can be allocated, nor enter the scratch list.
  321.  
  322.     Even though memory returned from AllocMem() IS aligned to 32 byte
  323.     boundaries, AllocVec'd memory isn't. It is still only long word
  324.     aligned because the first longword of the vector is used to keep
  325.     the size of the allocated memory. This doesn't hurt for the purpose 
  326.     this keyword was invented for; it is, even more, REQUIRED to work
  327.     like this because the vector size should be either in the PPC or
  328.     in the MC68K cache, but not in both.
  329.  
  330.     Due to the heavy fragmentation of memory when using this keyword,
  331.     it is recommended to use it only if absolutely necessary. The
  332.     standard PPC system software deals with the problem of overlapping
  333.     caches correctly so there's by default no need for this keyword.
  334.  
  335.  
  336.     This keyword works quite different from AllocP32. It doesn't use
  337.     "magic cookies" in any way and is written in a way compatible to
  338.     the - rather ugly - layers.library allocation methods (check the
  339.     developer.readme file in this archive for details about this). The
  340.     drawback of this compatibility is the rather high fragmentation,
  341.     it's even higher than without PoolMem. You have been warned!
  342. ______________________________________________________________________________
  343.  
  344.             For the advanced user.....
  345. ______________________________________________________________________________
  346.  
  347. Theory of operation:
  348.  
  349.     PoolMem splits all available memory in two blocks: One block is used 
  350. for the small memory snippets (always taken from there), the other block is used
  351. for huge allocations. This partition of the main memory is dynamic, i.e. each
  352. sub-pool can grow and shrink, depending on the memory requirements.
  353.  
  354. The "public/ANY" memory gets a special treatment. PoolMem manages a "scratch"
  355. list for tiny memory blocks taken from there. Instead of taking these tiny
  356. memory blocks always from the main memory, they are taken from this (global,
  357. though) memory pool and put back into this pool if they get freed. A special
  358. garbage collection task cleans this "scratch list" from time to time, or if
  359. it overruns. The main profit is taken from the layers.library, which uses to
  360. allocate tons of tiny snippets and is therefore the main cause for memory
  361. fragmentation.
  362.  
  363. The "chip" memory is treated a bit different. It's also split into two 
  364. distinct memory pools (small and large), but memory from the large pool
  365. is allocated in reverse direction - unless you run PoolMem with the
  366. ChipFwd keyword, of course; this happens for two reasons: First, it
  367. helps to keep the memory defragmentated, so the big pool can't run that
  368. easely into the small pool. Second, it works around a hardware bug of my
  369. computer (the refresh of the high end chip memory in my computer seems to
  370. be a bit buggy - some bits tend to flip if they aren't frequently accessed,
  371. for example by the DMA processor as display memory.)
  372.  
  373. For details about the PatchRAM program, check its readme file. As I said, if
  374. you run PoolMem, you're supposed to run PatchRAM as well. It helps PoolMem
  375. a lot in its job! Future versions of PoolMem will include this patch as
  376. well, but the current version is not yet supposed to be "final" in any
  377. way.
  378.  
  379. _________________________________________________________________________________
  380.  
  381. Additional programs:
  382.  
  383. The PoolMem program is still in a somewhat experimental stage, even though
  384. it's running stable for my system for more than two years now - I won't
  385. expect any serious bugs, though.
  386. However, if you like to see how PoolMem works and if it has any effects, I
  387. provided several extra programs:
  388.  
  389. ShowMem:        Shows the allocated/free memory in a graphical over-
  390.             view. For details, check the ShowMem readme and its
  391.             guide. (Available separately as well)
  392.  
  393. PatchRAM:        Modifies and improves the RAM disk. Shows the correct
  394.             size of the RAM drive which is then no longer 100%
  395.             full all the time.
  396.             For details, check the PatchRAM.readme.
  397.  
  398. FragMeter:        Calculates the fragmentation of your memory. The
  399.             output is given separately for each memory type.
  400.             A 100% fragmentation indicates that all the free
  401.             memory is messed up in tiny blocks of eight bytes
  402.             each (maximal fragmentation).
  403.             A Shannon-type approach is used to measure the
  404.             fragmentation (the algorithm calculates the Shannon
  405.             entropy of the memory blocks with the formula
  406.             sum += log(chunk->mc_Bytes/total)
  407.             If you know a better approach for measuring the
  408.             fragmentation, lemme now. This here seems at least
  409.             reasonable for me as a theoretical physicst... ;-)
  410.             
  411.             This program can be used to test the efficency of
  412.             PoolMem. My measurements indicate that the entropy is
  413.             about halved.
  414.  
  415. MemoryMess:        A program that tries to fragmentate the main memory
  416.             as bad as possible by allocating and freeing memory
  417.             in random order. Can be used together with the 
  418.             FragMeter to measure the efficiency of PoolMem or
  419.             with ShowMem to watch PoolMem at its job. Can be
  420.             canceled safely with ^C (Control-C). Does nothing
  421.             useful except that.
  422.  
  423. PatchReplyMsg:        Useful to find buggy programs, like XiPaint.
  424.             PatchReplyMsg will create a guru 0x0100001f if a
  425.             program attempts to reply an already de-allocated
  426.             message. Don't install it permanently, but use it
  427.             to find the reason for crashes.
  428.  
  429.  
  430. If you've ideas how to improve PoolMem, lemme know....
  431.  
  432. ______________________________________________________________________________
  433.  
  434. Guru meditations thrown by PoolMem:
  435.  
  436. 0x01000013        Scratch entry illegal.
  437.  
  438.             Some program invalidated the internal memory scratch
  439.             list of PoolMem - by overwriting memory that has been
  440.             deallocated before. An (in)famous example is XiPaint.
  441.             Run "PatchReplyMsg" and a debugger (e.g. COP) to check
  442.             for details.
  443.  
  444. 0x0100000f        MemHeader not found.
  445.  
  446.             Some program attempted to free a non-existing block
  447.             of memory. PoolMem wasn't able to locate
  448.             the MemHeader.
  449.  
  450.  
  451. 0x01000011        MemHeader insane.
  452.  
  453.             PoolMem found a MemHeader whose number of available
  454.             bytes does not match the size of its pool.
  455.  
  456.  
  457. 0x01000012        Invalid DeleteHeader (internal).
  458.  
  459.             Someone tried to deallocate the "large" memory pool.
  460.             This is an internal guru, shouldn't happen. 
  461.  
  462. 0x01000014        Memory Pools unordered.
  463.  
  464.             Someone changed the order of the memory blocks, the
  465.             large memory block is no longer in front of the
  466.             small memory pool.
  467.  
  468.  
  469. Additionally, PoolMem throws all standard exec guru's - the >1.3x routines
  470. replace the OS functions completely. As a side effect, PoolMem MUST BE RUN
  471. IN FRONT OF OTHER MEMORY TOOLS, especially RUN POOLMEM FIRST, MUNGWALL LATER.
  472.  
  473. ______________________________________________________________________________
  474.  
  475.                         The THOR-Software Licence
  476.  
  477.  
  478. This License applies to the computer programs known as "PoolMem", "ShowMem",
  479. "FragMeter", "MemoryMess" and "ShowMem".
  480. The "Program", below, refers to such program.
  481.  
  482.  
  483. The programs and files in this distribution are freely distributable
  484. under the restrictions stated below, but are also Copyright (c)
  485. Thomas Richter.
  486.  
  487.  
  488. Distribution of the Program by a commercial organization without written
  489. permission from the author to any third party is prohibited if any payment
  490. is made in connection with such distribution, whether directly
  491. (as in payment for a copy of the Program) or indirectly (as in payment
  492. for some service related to the Program, or payment for some product
  493. or service that includes a copy of the Program "without charge";
  494. these are only examples, and not an exhaustive enumeration of prohibited
  495. activities). However, the following methods of distribution involving
  496. payment shall not in and of themselves be a violation of this restriction:
  497.  
  498.  
  499. (i) Posting the Program on a public access information storage and
  500. retrieval service for which a fee is received for retrieving information
  501. (such as an on-line service), provided that the fee is not
  502. content-dependent (i.e., the fee would be the same for retrieving the same
  503. volume of information consisting of random data).
  504.  
  505.  
  506.  
  507. (ii) Distributing the Program on a CD-ROM, provided that the files
  508. containing the Program are reproduced entirely and verbatim on such
  509. CD-ROM, and provided further that all information on such CD-ROM be
  510. redistributable for non-commercial purposes without charge.
  511.  
  512.  
  513.  
  514. Everything in this distribution must be kept together, in original
  515. and unmodified form.
  516.  
  517.  
  518.  
  519.  
  520. Limitations.
  521.  
  522. THE PROGRAM IS PROVIDED TO YOU "AS IS," WITHOUT WARRANTY. THERE IS NO
  523. WARRANTY FOR THE PROGRAM, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
  524. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  525. PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. THE ENTIRE
  526. RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD
  527. THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  528. SERVICING, REPAIR OR CORRECTION.
  529.  
  530.  
  531.  
  532. IF YOU DO NOT ACCEPT THIS LICENCE, YOU MUST DELETE ALL FILES CONTAINED IN
  533. THIS ARCHIVE.
  534.  
  535. ______________________________________________________________________________
  536.  
  537. Have fun,
  538.     Thomas        June 1998
  539.